#! /bin/sh -v
#
# $AIST_Release: 0.9.0 $
# Copyright 2011 Information Technology Research Institute, National
# Institute of Advanced Industrial Science and Technology
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

local_tmpdir=/tmp/doalltmp.$$
hadoop_tmpdir=/tmp/doalltmp.$$

trap "rm -rf ${local_tmpdir}; hadoop fs -rmr ${hadoop_tmpdir}" 0

mkdir ${local_tmpdir}

mkinput() {
    cmd=$1
    target=${hadoop_tmpdir}/$2

    (eval $cmd > ${local_tmpdir}/input) && 
    hadoop fs -mkdir $target && 
    hadoop fs -copyFromLocal ${local_tmpdir}/input $target
}

mkinput 'python input/sum_input.py' sum &&
mkinput 'python input/100_input.py' 100 &&
mkinput 'sh input/person_input.sh'  person

if  [ $? -ne 0 ]; then
    echo "Can't make input" >&2
    exit 1
fi

hsccmd() {
    szscript=$1
    input=$2
    output=`echo $1 | sed 's|/|-|g'`

    ./hsc2.sh --text $szscript ${hadoop_tmpdir}/${input} ${hadoop_tmpdir}/${output} || exit 1
}

hsccmd scripts/andor.sz       person
hsccmd scripts/assign.sz      sum 
hsccmd scripts/container.sz   person
hsccmd scripts/eq.sz          sum
hsccmd scripts/for.sz         person
hsccmd scripts/funcs.sz       sum 
hsccmd scripts/ops.sz         person
hsccmd scripts/person.sz      person
hsccmd scripts/sum.sz         sum
hsccmd scripts/time.sz        person
hsccmd scripts/when.sz        person
hsccmd scripts/max.sz         100
hsccmd scripts/ndim_array.sz  person
hsccmd scripts/sample.sz      100
hsccmd scripts/emit-tuple.sz  100
hsccmd scripts/quantile.sz    100
hsccmd scripts/top.sz         100
hsccmd scripts/unique.sz      100
hsccmd scripts/type.sz        person
hsccmd scripts/userfunc.sz    person
hsccmd scripts/escape.sz      person
hsccmd scripts/inteq.sz       person
hsccmd scripts/tableparam.szl person

